layui.use(['table', 'jquery', 'laydate'], function () {
    const table = layui.table,
        $ = layui.jquery;

    //默认加载时执行
    findAll();
    findCodeByType('gender', $("#gender"));

    function findAll() {

        let code = $('#code').val();
        let username = $('#username').val();
        let gender = $("#gender option:selected").val();
        let params = {
            code: code,
            username: username,
            gender: gender,
        };

        let cols = [[
            {type: 'checkbox', fixed: 'left'}
            , {field: 'id', width: 80, title: 'ID', sort: true, fixed: 'left'}
            , {field: 'code', width: 100, title: '用户编号', sort: true}
            , {field: 'stuId', width: 100, title: '学号', sort: true}
            , {field: 'username', width: 140, title: '用户名'}
            , {
                field: 'avatar', width: 120, title: '头像', templet: function (e) {
                    //判断图片是否为空
                    e.avatar === null || e.avatar === undefined ? e.avatar = '/upload/img_null.png' : e.avatar;
                    return '<img src="' + e.avatar + '" width="80px" height="30px">'
                }
            }
            , {
                field: 'gender', width: 80, title: '性别', templet: e => {
                    return getGenderStatus(e.gender);
                }
            }
            , {field: 'phone', width: 160, title: '电话'}
            , {field: 'birthday', title: '生日', width: 160}
            , {
                field: 'degree', title: '学历', templet: e => {
                    return getDegreeStatus(e.degree);
                }
            }
            , {field: 'joinTime', title: '入学时间', width: 160}
            , {field: 'joinFrequency', title: '入学班次', width: 160}
            , {field: 'createTime', title: '创建时间', width: 160}
            , {field: 'updateTime', title: '更新时间', width: 160}
        ]];

        //发送请求
        table.render({
            elem: '#dataList'
            , url: STU_APP_URL + "/sign/findAllStudent"
            , where: params
            , method: 'get'
            , headers: HEADERS
            , request: REQUEST
            , response: RESPONSE
            , cellMinWidth: 80
            , height: 720
            , toolbar: '#toolbar'
            , skin: 'line'
            , even: true
            , page: true
            , limits: [5, 10, 20, 30, 50]
            , limit: 20
            , title: '用户数据表'
            , cols: cols
        });
    }

    //监听头工具栏事件
    table.on('toolbar(dataList)', function (obj) {
        const checkStatus = table.checkStatus(obj.config.id)
            , data = checkStatus.data; //获取选中的数据
        switch (obj.event) {
            case 'pointTo':
                startPointTo();
        }
    });

    /**
     * 查询
     */
    $('#query').on('click', function () {
        findAll()
    });

    /**
     * 重置
     */
    $('#reset').on('click', function () {
        $('#code').val('');
        $('#username').val('');
        $('#gender').val('');
    });

    /**
     * 开始点到
     */
    function startPointTo() {
        //获取当前登录用户
        let result = loginUserAjax();
        let userCode = result.data.code;
        sessionStorage.setItem("userCode", userCode);
        layer.open({
            title: '小组成员',
            //调整弹窗大小
            area: ["100%", "100%"],
            //点击旁边地方自动关闭
            shadeClose: true,
            anim: 2,
            type: 2,
            content: 'signStudentTable.html'
        })
    }

});